package com.pwx.web.controller;

import com.pwx.common.Const;
import com.pwx.utils.SendCheckCod;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * Copyright (C),2021-2022,亚瑟王
 * FileName: SystemController
 * Author: saber
 * Date:2022/9/29 20:38
 */
@Controller
@RequestMapping("/sys")
public class SystemController {

    @RequestMapping(value = "/sendMsg/{phoneNumber}",method = RequestMethod.POST)
    public void sendMsg(@PathVariable("phoneNumber") String phoneNumber, HttpSession session){
        System.out.println(phoneNumber);
        String code = SendCheckCod.SendCode(phoneNumber);
        session.setMaxInactiveInterval(120);
        session.setAttribute(Const.CKECK_CODE,code);
    }

    @RequestMapping(value = "/checkCode",method = RequestMethod.POST)
    @ResponseBody
    public String checkCode(String code,HttpSession session){
        String encryptCode = (String) session.getAttribute(Const.CKECK_CODE);
        boolean f = SendCheckCod.checkCode(code,encryptCode);
        if (f){
            return "1";
        }else {
            return "0";
        }
    }

} 
